import request from '@/utils/request'
import type {GetSpuListApiResponse,
    GetSpuListApiParams,
    BaseSaleAttrList,
    SpuItem, 
    SpuImageList, 
    SpuSaleAttrList} from './model/spuModel'

enum Api {
    getSpuList = "/admin/product",
    getBaseSaleAttrList = "/admin/product/baseSaleAttrList",
    saveSpu = "/admin/product/saveSpuInfo",
    updateSpu = "/admin/product/updateSpuInfo",
    getSpuImageList = "/admin/product/spuImageList",
    getSpuSaleAttrList = "/admin/product/spuSaleAttrList",
}

// 获取Spu列表
export const getSpuListApi = ({page,limit,category3Id}:GetSpuListApiParams)=>{
    return request.get<any,GetSpuListApiResponse>(`${Api.getSpuList}/${page}/${limit}`,{
        params:{
            category3Id
        }
    })
}

// 获取基础销售属性列表
export const getBaseSaleAttrListApi = ()=>{
    return request.get<any,BaseSaleAttrList>(Api.getBaseSaleAttrList)
}

// 添加Spu
export const saveSpuApi = (data:SpuItem)=>{
    return request.post<any,null>(Api.saveSpu,data)
}

// 更新Spu
export const updateSpuApi = (data:SpuItem)=>{
    return request.post<any,null>(Api.updateSpu,data)
}

// 获取图片列表
export const getSpuImageListApi = (id:number)=>{
    return request.get<any,SpuImageList>(`${Api.getSpuImageList}/${id}`)
}

// 获取销售属性列表
export const getSpuSaleAttrListApi = (id:number)=>{
    return request.get<any,SpuSaleAttrList>(`${Api.getSpuSaleAttrList}/${id}`)
}